package com.neuedu.tx.service;

import com.neuedu.tx.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * 项目：      spring-framework
 * 类名:       AccountService
 * 创建时间：  2024/3/14 14：26
 * 描述 :
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
@Service
public class AccountService {
    @Autowired
    AccountDao accountDao;


    /***
     * 转账
     * @return
     */
    @Transactional(transactionManager="txManager",propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
    public boolean transfer(){

        int id1 = 1 ;
        double amount1 = -500;
        int count1 = accountDao.updateAccount(id1,amount1);

//        System.out.println("与蜀国打仗，会计支出 打算下个月涨工资，比 例是： " + (0 /0));

        int id2 = 2;
        double amount2 = 500;
        int count2 = accountDao.updateAccount(id2,amount2);

        return count1 + count2 == 2;
    }


    public void select(){

    }
}
